<?php
/**
* @desc 注册用户表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class UserForm extends BaseForm
{
	public $username;
	public $nick_name;
	public $email;
	public $mobile;
	public $status;
	//表单规则
	public function rules()
	{
		return array(
			array('username, nick_name, email, mobile, status', 'required', 'message'=>'必填字段不能为空'),
			array('username', 'unique' , 'on'=>'add', 'className'=>'User', 'message'=>'用户名已存在'),
			array('email', 'match', 'pattern'=>"/^(([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?))$/",'message'=>'请输入正确邮箱'),
			array('mobile', 'match', 'pattern'=>"/^((1(([35][0-9])|(47)|[8][01236789]))\d{8})$/",'message'=>'请输入正确手机号'),
			array('status', 'boolean', 'message'=>'用户状态为布尔值'),
		);
	}
	//写入数据
	public function saveData(){
		$model = new User;
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		$data = $this->attributes;
		$data['author'] = $userInfo['username'];
		return $model->insertUser($data);
	}
	//修改数据
	public function editData($id){
		$model = new User;
		return $model->editUser($id, $this->attributes);
	}
}
